 package tools;

 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.InputStreamReader;
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.UnknownHostException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Enumeration;

















 public class IPAddressTool
 {
   public static long dottedQuadToLong(String dottedQuad) throws RuntimeException {
/*  33 */     String[] quads = dottedQuad.split("\\.");
/*  34 */     if (quads.length != 4) {
/*  35 */       throw new RuntimeException("Invalid IP Address format.");
     }
/*  37 */     long ipAddress = 0L;
/*  38 */     for (int i = 0; i < 4; i++) {
/*  39 */       ipAddress += (Integer.parseInt(quads[i]) % 256) * (long)Math.pow(256.0D, (4 - i));
     }
/*  41 */     return ipAddress;
   }








   public static String longToDottedQuad(long longIP) throws RuntimeException {
/*  52 */     StringBuilder ipAddress = new StringBuilder();
/*  53 */     for (int i = 0; i < 4; i++) {
/*  54 */       int quad = (int)(longIP / (long)Math.pow(256.0D, (4 - i)));
/*  55 */       longIP -= quad * (long)Math.pow(256.0D, (4 - i));
/*  56 */       if (i > 0) {
/*  57 */         ipAddress.append(".");
       }
/*  59 */       if (quad > 255) {
/*  60 */         throw new RuntimeException("Invalid long IP address.");
       }
/*  62 */       ipAddress.append(quad);
     }
/*  64 */     return ipAddress.toString();
   }
   public static String getLocalIP() {
     byte[] ipAddr;
/*  68 */     String ipAddrStr = "";

     try {
/*  71 */       ipAddr = InetAddress.getLocalHost().getAddress();
/*  72 */     } catch (UnknownHostException e) {
/*  73 */       return null;
     }
/*  75 */     for (int i = 0; i < ipAddr.length; i++) {
/*  76 */       if (i > 0) {
/*  77 */         ipAddrStr = ipAddrStr + ".";
       }
/*  79 */       ipAddrStr = ipAddrStr + (ipAddr[i] & 0xFF);
     }
/*  81 */     return ipAddrStr;
   }

   public static void getLocalIPs() {
     try {
/*  86 */       Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
/*  87 */       while (netInterfaces.hasMoreElements()) {
/*  88 */         NetworkInterface nif = netInterfaces.nextElement();
/*  89 */         Enumeration<InetAddress> iparray = nif.getInetAddresses();
/*  90 */         while (iparray.hasMoreElements()) {
/*  91 */           System.out.println("IP:" + ((InetAddress)iparray.nextElement()).getHostAddress());
         }
       }
/*  94 */     } catch (Exception e) {
/*  95 */       System.out.println(e.getMessage());
     }
   }






   public static String getCPUSerial() {
/* 105 */     String result = "";
     try {
/* 107 */       File file = File.createTempFile("CPUSerial", ".vbs");
/* 108 */       file.deleteOnExit();
/* 109 */       FileWriter fw = new FileWriter(file);
/* 110 */       String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\nSet colItems = objWMIService.ExecQuery _ \n   (\"Select * from Win32_Processor\") \nFor Each objItem in colItems \n    Wscript.Echo objItem.ProcessorId \n    exit for  ' do the first cpu only! \nNext \n";





/* 116 */       fw.write(vbs);
/* 117 */       fw.close();
/* 118 */       Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
/* 119 */       BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
       String line;
/* 121 */       while ((line = input.readLine()) != null) {
/* 122 */         result = result + line;
       }
/* 124 */       input.close();
/* 125 */       file.delete();
/* 126 */     } catch (Exception e) {
/* 127 */       System.out.println(e.toString());
/* 128 */       result = null;
     }
/* 130 */     if (result == null || result.trim().length() < 1) {
/* 131 */       result = null;
     }
/* 133 */     return result.trim();
   }







   public static String getHardDiskSN(String drive) {
/* 143 */     String result = "";
     try {
/* 145 */       File file = File.createTempFile("disksn", ".vbs");
/* 146 */       file.deleteOnExit();
/* 147 */       FileWriter fw = new FileWriter(file);
/* 148 */       String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\nSet colDrives = objFSO.Drives\nSet objDrive = colDrives.item(\"" + drive + "\")\nWscript.Echo objDrive.SerialNumber";





/* 154 */       fw.write(vbs);
/* 155 */       fw.close();
/* 156 */       Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
/* 157 */       BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
       String line;
/* 159 */       while ((line = input.readLine()) != null) {
/* 160 */         result = result + line;
       }
/* 162 */       input.close();
/* 163 */       file.delete();
/* 164 */     } catch (Exception e) {
/* 165 */       result = null;
     }
/* 167 */     return result.trim();
   }

   public static String getkey() {
/* 171 */     String result = "gCrmrxYXZnbXy7FW";
/* 172 */     String cpu = getCPUSerial();
/* 173 */     String diskSN = getHardDiskSN("c");
/* 174 */     String mac = MacAddressTool.getMacAddress(false);
/* 175 */     if (cpu != null)
     {

/* 178 */       result = result + cpu;
     }
/* 180 */     if (diskSN != null) {
/* 181 */       result = result + diskSN;
     }
/* 183 */     if (mac != null) {
/* 184 */       result = result + mac;
     }
/* 186 */     return encryptToMD5(result.trim());
   }







   public static String encryptToMD5(String info) {
/* 196 */     byte[] digesta = null;

     try {
/* 199 */       MessageDigest alga = MessageDigest.getInstance("MD5");

/* 201 */       alga.update(info.getBytes());

/* 203 */       digesta = alga.digest();
/* 204 */     } catch (NoSuchAlgorithmException e) {
/* 205 */       e.printStackTrace();
     }


/* 209 */     return byte2hex(digesta);
   }







   public static String byte2hex(byte[] b) {
/* 219 */     String hs = "";
/* 220 */     String stmp = "";
/* 221 */     for (byte aB : b) {
/* 222 */       stmp = Integer.toHexString(aB & 0xFF);
/* 223 */       if (stmp.length() == 1) {
/* 224 */         hs = hs + "0" + stmp;
       } else {
/* 226 */         hs = hs + stmp;
       }
     }
/* 229 */     return hs.toUpperCase();
   }
 }


/* Location:              C:\PGX\Server.jar!\tools\IPAddressTool.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */